package com.hmy.uaa.common.security;


import com.hmy.uaa.mapper.UserMapper;
import com.hmy.uaa.po.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Component;

import java.util.Collections;

/**
 * 根据用户id认证
 */
@Component
public class UserIdDetailsService implements UserDetailsService {
    @Autowired
    private UserMapper userMapper;


    @Override
    public UserDetails loadUserByUsername(String uid) throws UsernameNotFoundException {

        User user = userMapper.getUserInfo(uid);
        if (user == null) {
            throw new UsernameNotFoundException("用户名或密码错误");
        }
        return new com.hmy.uaa.common.security.User(user.getPhone(), user.getPassword(), Collections.emptyList());
    }

}
